// TypeScript file
class startView extends egret.DisplayObjectContainer {
    public constructor() {
        super();
        this.width = 750;
        this.height = 1334;
        this.init();
    }

    private image: egret.Bitmap;

    private init() {
        this.initButton("重置图片", 20, 20, this.initImage);
        this.initButton("透明度", 20, 1000, this.updateAlpha);
        this.initButton("位移X", 200, 1000, this.updateX);
        this.initButton("缓动", 400, 1000, this.updateY);
        this.initButton("设置锚点", 20, 1100, this.updateAnchor);
        this.initButton("旋转", 200, 1100, this.updateRotation);
        this.initButton("缩放", 400, 1100, this.updatescaleX);
        this.initButton("显示", 20, 1200, this.updatevisible);
        this.initButton("斜切X", 200, 1200, this.updateskewX);
        this.initButton("斜切Y", 400, 1200, this.updateskewY);
        this.initImage();
    }



    //测试
    private test() {
        console.log("测试")
    }

    //斜切

    private updateskewX() {
        if (this.image) {
            
            this.image.skewX += 10;
        }
    }
    private updateskewY() {
        if (this.image) {
            this.image.skewY += 10;
        }
    }

    //显示
    private updatevisible() {
        if (this.image) {
            this.image.visible = !this.image.visible;
        }
    }

    //缩放
    private updatescaleX() {
        if (this.image) {
            this.image.scaleX = this.image.scaleY = this.image.scaleX > 1 ? 1 : this.image.scaleX == 1 ? 0.5 : 2;
        }
    }

    //旋转
    private updateRotation() {
        if (this.image) {
            this.image.rotation += 10;
        }
    }

    //设置锚点
    private updateAnchor() {
        if (this.image) {
            this.image.anchorOffsetX = this.image.width / 2;
            this.image.anchorOffsetY = this.image.height / 2;
        }
    }

    //缓动
    private updateY() {
        if (this.image) {
            egret.Tween.get(this.image).to({ alpha: 0 }, 1000, egret.Ease.sineIn);
        }
    }

    //位移
    private updateX() {
        if (this.image) {
            if (this.image.x >= 200) {
                this.image.x = 0;
            }
            this.image.x += 10;
        }
    }

    //透明度
    private updateAlpha() {
        if (this.image) {
            if (this.image.alpha <= 0) {
                this.image.alpha = 1;
            }
            this.image.alpha -= 0.2;
        }
    }

    //初始化图片
    private initImage() {
        if (this.image) {
            this.removeChild(this.image);
            this.image = null;
        }
        this.image = new egret.Bitmap;
        this.image.texture = RES.getRes("1_jpg");
        this.image.y = 100;
        this.addChild(this.image);
    }

    //通用按钮
    private initButton(textContent, x, y, callback) {
        var text: egret.TextField = new egret.TextField();
        text.text = textContent;
        text.textColor = 0x000000;
        text.background = true;
        text.backgroundColor = 0x03f425;
        text.x = x;
        text.y = y;
        text.touchEnabled = true;
        text.addEventListener(egret.TouchEvent.TOUCH_TAP, callback, this);
        this.addChild(text);
    }
}